﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Text;

namespace paper.evisa99.com.Controllers
{
    public class CAController : Controller
    {
        Class.Record record = new Class.Record();
        Class.Html html = new Class.Html();
        Class.Http http = new Class.Http();
        Class.Utility utility = new Class.Utility();
        static string CountryCode = "CA";
        //用户资料库说明：Member(核心资料),Info_Personal-PS(基本资料),Info_Experience-EX(工作教育),Info_Family-FM(家庭信息)
        //Info_Passport-PP(护照信息),Info_Relation-RL(亲属信息),Info_Colleague-CO(同行人信息),Info_ItineraryXX-IT(行程)
        ///====================================================================web
        public ActionResult Start(string id, string id2, string id3, string key, string cf, string un)
        {
            //param
            string Merchant = id;
            string AccountID = id2;
            string MemberID = id3;
            string ComeFrom = cf;
            string UserName = un;
            if (!Class.Authority.ValidKey(key, Merchant + AccountID + MemberID)) { Response.Write("参数提交错误"); Response.End(); }
            //declare
            DataTable memberinfo, itinfo;
            //data
            Class.DB.Conn.Open();
            memberinfo = record.GetMemberInfo(MemberID);
            //itinfo = record.GetItineraryInfo(MemberID, CountryCode);
            Class.DB.Conn.Close();
            //html
            //--判断是否有该客户-基本记录，没有的新建
            if (memberinfo.Rows.Count == 0)
            {
                record.CreateMember(Merchant, AccountID, MemberID, ComeFrom, UserName, "", "", "", "", "");
            }
            //--判断是否有该客户-行程记录，没有的新建
            //if (itinfo.Rows.Count == 0)
            //{
            //    record.CreateItinerary(MemberID, CountryCode);
            //}
            //--判断该资料是否锁定
            //if (memberinfo.Rows.Count > 0)
            //{
            //    if (memberinfo.Rows[0]["IsUsed"].ToString() != "True")
            //    {
            //        Response.Redirect("/Home/NoAllowed");
            //    }
            //}
            //output
            //--如果不需要显示确认页
            Response.Redirect("/" + CountryCode + "/Form/PS/" + MemberID + "/?key=" + Class.Authority.GenKey(MemberID + "PS"));
            return View();
        }
        ///--------------------------------------------------------------------------------------------PS
        public ActionResult Form(string id, string id2, string key)
        {
            //param
            string InfoChannel = id.ToUpper();
            string MemberID = id2;
            if (!Class.Authority.ValidKey(key, MemberID + InfoChannel)) { Response.Write("参数提交错误"); Response.End(); }
            //declare
            DataTable memberinfo, psinfo, exinfo, fminfo, ppinfo, rlinfo, coinfo, itinfo;
            StringBuilder box = new StringBuilder();
            StringBuilder js = new StringBuilder();
            string NotRequired = "", OnReadyScript = "";
            //data
            Class.DB.Conn.Open();
            memberinfo = record.GetMemberInfo(MemberID);
            Class.DB.Conn.Close();
            //html
            //--预定义JS
            js.AppendLine("<script type=\"text/javascript\" src=\"/content/scripts/web/valid.js\"></script>");
            js.AppendLine("<script type=\"text/javascript\" src=\"/content/scripts/" + CountryCode.ToLower() + "/" + InfoChannel.ToLower() + ".js\"></script>");
            //--生成填写表格
            switch (InfoChannel)
            {
                case "PS":
                    OnReadyScript = "";
                    NotRequired = "|AnotherSurname|AnotherPersonalName|Email|";
                    //
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "姓氏", "Surname", "填写中文", 10, "CN", "", "", false, true));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "名称", "PersonalName", "填写中文", 10, "CN", "", "", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "曾用姓氏", "AnotherSurname", "填写中文", 10, "CN", "", "", false, false));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "曾用名称", "AnotherPersonalName", "填写中文", 10, "CN", "", "", false, false));
                    box.AppendLine(html.HelpCell("没有则不填写"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.DropDownList(ref memberinfo, "", "性别", "Gender", "先生,女士", "", "", false, true));
                    box.AppendLine(html.DateYMD(ref memberinfo, "", "出生日期", "Birthday", "2000-1-1", "1901-1-1", DateTime.Now.ToShortDateString(), "", "", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "身份证", "IdCard", "", 18, "EN", "", "", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.ChinaCity("", "出生国家", "BirthPrivence", "BirthPrivence,BirthCity,BirthDistrict", "no", "", "", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell("只能办理中国城市"));
                    box.AppendLine(html.ChinaCity("", "出生省份", "BirthCity", "BirthPrivence,BirthCity,BirthDistrict", "no", "", "", false, true));
                    box.AppendLine(html.ChinaCity("", "出生城市", "BirthDistrict", "BirthPrivence,BirthCity,BirthDistrict", "no", "", "", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.ChinaCity("", "现居住国家", "AddressPrivence", "AddressPrivence,AddressCity,AddressDistrict", "no", "", "", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell("只能办理中国城市"));
                    box.AppendLine(html.ChinaCity("", "现居住省份", "AddressCity", "AddressPrivence,AddressCity,AddressDistrict", "no", "", "", false, true));
                    box.AppendLine(html.ChinaCity("", "现居住城市", "AddressDistrict", "AddressPrivence,AddressCity,AddressDistrict", "no", "", "", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "详细地址", "Address", "不写省份及地市", 100, "Fill", "", "", true, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "邮政编码", "PostCode", "", 6, "NUM", "", "", false, false));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "电子邮箱", "Email", "如有请填写", 50, "Email", "", "", false, false));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "手机号码", "Mobile", "", 11, "NUM", "", "", false, true));
                    box.AppendLine(html.HelpCell("儿童填写家长的邮箱、电话"));
                    box.AppendLine(html.DropDownList(ref memberinfo, "", "备用电话类型", "AltPhoneType", "家庭电话,手机,办公电话", "", "", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "备用电话区号", "AltPhoneCode", "区号", 4, "NUM", "", "", false, true));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "备用电话号码", "AltPhone", "电话号码", 20, "NUM", "", "", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    //是否有美签
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.JudgeList(ref memberinfo, "", "现在拥有有效的美国或加拿大签证，或者十年内去过加拿大？", "PrecheckMemo", "是,否", "judgePrecheckMemo", "", "", true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    //是否是公务员
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.JudgeList(ref memberinfo, "", "您是否是公务员？", "IsCivilServant", "是,否", "JudgeIsCivilServant", "", "", true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    //是否是退役军官
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.JudgeList(ref memberinfo, "", "您是否是退役军官？", "IsExsoldier", "是,否", "JudgeIsExsoldier", "", "", true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    break;
                case "EX":
                    //OnReadyScript = "<script>$(function () {JudgeWorkNow();JudgeIsLastWork();JudgeIsLastWork2();JudgeIsEducation();JudgeIsEducation2();JudgeIsEducation3();JudgeEtc02();JudgeEtc03();})</script>";
                    NotRequired = "|CurrentOccupation_EN|CurrentEntryDate|CurrentCompany_EN|CurrentEducationSchool_EN";
                    NotRequired += "|LastCompany|LastCompany_EN|LastCompany2|LastCompany_EN2|LastCompany3|LastCompany_EN3";
                    NotRequired += "|EducationSchool|EducationSchool_EN|EducationSchool2|EducationSchool_EN2|EducationSchool3|EducationSchool_EN3|";
                    //当前工作
                    box.AppendLine(html.GroupStart());
                    box.AppendLine(html.JudgeList(ref memberinfo, "", "您目前的职业是？", "WorkNow", "工作,无业,自由职业,家庭主妇,学生,学龄前,退休", "JudgeWorkNow", "", "", true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_1", false));
                    box.AppendLine(html.TextCaution("无业人员请在下面填写过去十年的工作情况，没有工作请填无"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_2", false));
                    box.AppendLine(html.TextCaution("自由职业请在下面填写过去十年的工作情况，没有工作请填无"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_3", false));
                    box.AppendLine(html.TextCaution("家庭主妇请在下面填写过去十年的工作情况，没有工作请填无"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_4", false));
                    box.AppendLine(html.TextCaution("退休人员请在下面填写退休前十年内的工作情况"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_5", false));
                    box.AppendLine(html.TextCaution("退休人员请在下面填写退休前十年内的工作情况"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_6", false));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "中文职务名称", "CurrentOccupation", "", 20, "Fill", "WorkNow", "工作", false, true));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "英文职务名称", "CurrentOccupation_EN", "如果有请填写", 30, "EN", "WorkNow", "工作", false, false));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.WorkDuty( "", "工作性质", "CurrentDuty",  "WorkNow", "工作",  true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前单位名称", "CurrentCompany", "", 30, "Fill", "WorkNow", "工作", true, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前单位名称（英文）", "CurrentCompany_EN", "填写英文", 100, "EN", "WorkNow", "工作", true, false));
                    box.AppendLine(html.HelpCell("如有专属英文需填写"));
                    box.AppendLine(html.ChinaCity("", "当前单位所在国家", "CurrentCompanyCountry", "CurrentCompanyCountry,CurrentCompanyPrivence,CurrentCompanyCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.ChinaCity("", "当前单位所在省份", "CurrentCompanyPrivence", "CurrentCompanyCountry,CurrentCompanyPrivence,CurrentCompanyCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.ChinaCity("", "当前单位所在城市", "CurrentCompanyCity", "CurrentCompanyCountry,CurrentCompanyPrivence,CurrentCompanyCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前单位地址", "CurrentCompanyAddress", "不写省份及地市", 70, "Fill", "WorkNow", "工作", true, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.DateYMD(ref memberinfo, "", "当前单位入职日期", "CurrentEntryDate", "2000-1-1", "1901-1-1", DateTime.Now.ToShortDateString(), "WorkNow", "工作", false, true));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前月薪", "CurrentIncome", "仅输入数字", 10, "NUM", "WorkNow", "工作", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextCaution("以上工作信息必须和在职证明内的信息保持一致，否则有可能造成拒签；"));
                    box.AppendLine(html.TextCaution("系统会根据上述信息帮您生成好在职证明模板，信息提交后请到个人中心下载。"));
                    box.AppendLine(html.GroupEnd());
                    box.AppendLine(html.GroupStart("WorkNow_7", false));
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前学校名称", "CurrentEducationSchool", "", 30, "Fill", "WorkNow", "学生", true, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前学校名称（英文）", "CurrentEducationSchool_EN", "填写英文", 100, "EN", "WorkNow", "学生", true, false));
                    box.AppendLine(html.HelpCell("如有专属英文需填写"));
                    box.AppendLine(html.ChinaCity("", "当前学校所在国家", "CurrentEducationCountry", "CurrentEducationCountry,CurrentEducationPrivence,CurrentEducationCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.ChinaCity("", "当前学校所在省份", "CurrentEducationPrivence", "CurrentEducationCountry,CurrentEducationPrivence,CurrentEducationCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.ChinaCity("", "当前学校所在城市", "CurrentEducationCity", "CurrentEducationCountry,CurrentEducationPrivence,CurrentEducationCity", "yes", "WorkNow", "工作", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "当前学校地址", "CurrentEducationAddress", "不写省份及地市", 100, "Fill", "WorkNow", "学生", true, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.TextBox(ref memberinfo, "", "所学专业", "CurrentEducationMajor", "", 100, "Fill", "WorkNow", "学生", false, true));
                    box.AppendLine(html.DropDownList(ref memberinfo, "", "所学学历", "Gender", "博士,硕士,大学,高中,中学,小学", "WorkNow", "学生", false, true));
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.DateYMD(ref memberinfo, "", "当前学校入学日期", "CurrentEducationEntryDate", "2000-1-1", "1901-1-1", DateTime.Now.ToShortDateString(), "WorkNow", "学生", false, true));
                    box.AppendLine(html.EmptyBlank());
                    box.AppendLine(html.HelpCell());
                    box.AppendLine(html.GroupEnd());


                    break;
            }
            //output
            ViewBag.CountryCode = CountryCode;
            ViewBag.InfoChannel = InfoChannel;
            ViewBag.MemberID = MemberID;
            //
            ViewBag.Topic = utility.GetTopic(CountryCode);
            ViewBag.Subject = "请填写" + utility.GetSubject(InfoChannel);
            ViewBag.NaviLinks = utility.GetNaviLinks(CountryCode, InfoChannel, MemberID);
            //
            ViewBag.HtmlForm = box.ToString();
            ViewBag.PredefinedJavascript = js.ToString();
            ViewBag.NotRequired = NotRequired;
            ViewBag.OnReadyScript = OnReadyScript;
            return View();
        }
        ///--------------------------------------------------------------------------------------------

        ///====================================================================h5
    }
}
